package cn.acac.yygh.hosp.controller.admin;

import cn.acac.yygh.hosp.service.HospitalService;
import cn.acac.yygh.model.hosp.Hospital;
import cn.acac.yygh.result.R;
import cn.acac.yygh.vo.hosp.HospitalQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/hosp")
@Api("第三方医院的基本操作")
public class HospitalController {

    @Autowired
    private HospitalService hospitalService;

    /**
     * 根据id查询医院的详细信息
     * @param id
     * @return
     */
    @ApiOperation("根据id查询医院的详细信息")
    @GetMapping("/{id}")
    public R findHospitalById(@PathVariable String id){
        Hospital hospital = hospitalService.findHospitalById(id);
        return R.ok().setData("hospital",hospital);
    }

    /**
     * 根据id修改医院的状态
     * @param id
     * @param status
     * @return
     */
    @ApiOperation(value = "根据id修改医院的状态")
    @PutMapping("/{id}/{status}")
    public R updateStatus(@PathVariable(value = "id")String id,
                          @PathVariable(value = "status") Integer status){
        hospitalService.updateStatus(id,status);
        return R.ok();
    }

    /**
     * 将查询的第三方医院的信息返回给前端
     * @param pageNum
     * @param pageSize
     * @param hospitalQueryVo
     * @return
     *
     */
    @ApiOperation("将查询的第三方医院的信息返回给前端")
    @GetMapping("/selectPage/{pageNum}/{pageSize}")
    public R selectPage(@PathVariable("pageNum")Integer pageNum,
                        @PathVariable("pageSize")Integer pageSize,
                        HospitalQueryVo hospitalQueryVo){
        Page<Hospital> hospitalPage =  hospitalService.findHospitalPage(pageNum,pageSize,hospitalQueryVo);
        return R.ok().setData("pages",hospitalPage.getContent()).setData("total",hospitalPage.getTotalElements());
    }
}
